package com.yinhe.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.system.domain.YhBudget;
import com.yinhe.system.service.IYhBudgetService;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;

/**
 * 预算申请Controller
 * 
 * @author yinhe
 * @date 2022-07-26
 */
@RestController
@RequestMapping("/system/budget")
public class YhBudgetController extends BaseController
{
    @Autowired
    private IYhBudgetService yhBudgetService;

    /**
     * 查询预算申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:budget:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhBudget yhBudget)
    {
        startPage();
        List<YhBudget> list = yhBudgetService.selectYhBudgetList(yhBudget);
        return getDataTable(list);
    }

    /**
     * 导出预算申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:budget:export')")
    @Log(title = "预算申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhBudget yhBudget)
    {
        List<YhBudget> list = yhBudgetService.selectYhBudgetList(yhBudget);
        ExcelUtil<YhBudget> util = new ExcelUtil<YhBudget>(YhBudget.class);
        util.exportExcel(response, list, "预算申请数据");
    }

    /**
     * 获取预算申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:budget:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhBudgetService.selectYhBudgetById(id));
    }

    /**
     * 新增预算申请
     */
    @PreAuthorize("@ss.hasPermi('system:budget:add')")
    @Log(title = "预算申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhBudget yhBudget)
    {
        return toAjax(yhBudgetService.insertYhBudget(yhBudget));
    }

    /**
     * 修改预算申请
     */
    @PreAuthorize("@ss.hasPermi('system:budget:edit')")
    @Log(title = "预算申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhBudget yhBudget)
    {
        return toAjax(yhBudgetService.updateYhBudget(yhBudget));
    }

    /**
     * 删除预算申请
     */
    @PreAuthorize("@ss.hasPermi('system:budget:remove')")
    @Log(title = "预算申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhBudgetService.deleteYhBudgetByIds(ids));
    }
}
